<template>
  <div class="code">
    <img src="../assets/images/code.jpg" alt="">
  </div>
</template>

<script>
  import { requestCode } from '../api/api'
  export default {
    name: 'code',
    data () {
      return {}
    },
    mounted: function () {
      this.$nextTick(function () {
        this.loadData()
      })
    },
    methods: {
      loadData: function () {
        let e = this
        requestCode(this.$route.query.driver, this.$route.query.code, {}).then((res) => {
          const userInfo = res.data.oauth_user_info
          const token = res.data.access_token
          window.localStorage.setItem('user', JSON.stringify(userInfo))
          window.localStorage.setItem('accessToken', token)
          if (window.localStorage.getItem('accessToken')) {
            e.$router.push({ name: 'GetLocation' })
          }
        })
      }
    }
  }
</script>

<style scoped lang="less">
  .code{
    width: 100%;
    height: 100%;
    img{
      width: 100%;
      height: 100%;
      display: block;
      overflow: hidden;
    }
  }
</style>
